// 根据数组计算
import { isQueue, _mid, _dis, _atan, _polar } from './index.js'

// 镜像
// Angle of Refraction折射角
// index of Refraction折射角
export const _mirror = (p, o, radio = 1, refraction = 0) => {
  if (isQueue(p)) {
    return p.map(t => _mirror(t, o, radio, refraction))
  }
  if (refraction) {
    let r = _dis(p, o) * radio
    let a = _atan(p, o)
    return _polar(o, r, a + refraction)
  }
  if (radio === 1) {
    return [2 * o[0] - p[0], 2 * o[1] - p[1]]
  }
  return [(radio + 1) * o[0] - radio * p[0], (radio + 1) * o[1] - radio * p[1]]
}
// 边镜像
export const edgeMirror = (points, options) => {
  let {
    level,
    ratio = 1,
    startPoint,
    startIndex,
    refraction,
    r = 100
  } = options
  let midPoints = _mid(points)
  return midPoints.map((t, index) => {
    return _mirror(points, t, ratio, refraction)
    // let r2 = r * ratio
    // let o = _mirror(options.o, t, ratio, refraction)
    // let mirrorPoints = _mirror(points, t, ratio, refraction)
    // return mirrorPoints
    // return {
    //   points: mirrorPoints,
    //   o,
    //   r: r2,
    //   index
    // }
    // this.draw(
    //   Object.assign({}, this.options, {
    //     _points: mirrorPoints,
    //     o,
    //     r,
    //     fractal: {
    //       startPoint: t,
    //       startIndex: index,
    //       ...options,
    //       level,
    //       use: level > 1,
    //     },
    //   })
    // )
  })
}